# 4 - 3 数值微分
import numpy as np
import matplotlib.pyplot as plt

def f(x):
    return 0.01*x**2 + 0.1*x

def numerical_diff(f, x):
    h = 1e-4 # 0.0001
    return (f(x+h) - f(x-h)) / (2*h)

if __name__ == '__main__':
    x = np.arange(0.0, 20.0, 0.1)
    y = f(x)
    dy = numerical_diff(f, x)
    plt.plot(x, y)
    plt.plot(x, dy)
    plt.show()
    plt.xlabel('x')
    plt.ylabel('f(x)')
    plt.plot(x, y)
    plt.show()